package com.lrl.security.filter;

import org.springframework.stereotype.Component;
import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * @author LRL
 * 过滤器
 */
//@Component
public class TimeFilter implements Filter {
    /**
     * 初始化
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time filter init");
    }

    /**
     * 处理过滤器逻辑
     * @param request
     * @param response
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("time filter start");
        long start = System.currentTimeMillis();
        filterChain.doFilter(request,response);
        System.out.println("time filter 耗时:"+(System.currentTimeMillis() - start));
        System.out.println("time filter finish");
    }

    /**
     * 销毁
     */
    @Override
    public void destroy() {
        System.out.println("time filter destroy");
    }
}
